xxxxxxxxxx### This dataset contains the information on south-asian countries happiness report. It has the following indexes of happiness. Life LadderGDPSocial supportHealthy life expectancy at birthFreedom to make life choicesGenerosityPerception of corrouption Positive effect Negative effectLife Ladder GDP Social support Healthy life expectancy at birth Freedom to make life choices Generosity Perception of corrouption Positive effect Negative effect
xxxxxxxxxx#### Approach: get the data from kaggle: https://www.kaggle.com/ajaypalsinghlo/world-happiness-report-2021 Load the data in dataframe. Drop the year column from the dataset and taking average of the all other column. Create a list of South Asian countries and make another dataframe with those countries in it. Rank the data by coountries based on the indexes one by one. create a table and visualize the data using plotly. get the data from kaggle: https://www.kaggle.com/ajaypalsinghlo/world-happiness-report-2021
Load the data in dataframe.
Drop the year column from the dataset and taking average of the all other column.
Create a list of South Asian countries and make another dataframe with those countries in it.
Rank the data by coountries based on the indexes one by one.
create a table and visualize the data using plotly.import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport plotly.figure_factory as ffimport plotly.express as pxdf1=pd.read_csv(r"C:\Users\shali\Documents\World_happiness\world-happiness-report.csv")df1.head(10)df1.columnsdf1['Country name'].unique()new_df1=df1.groupby('Country name').agg('mean').reset_index()xxxxxxxxxxnew_df1=new_df1.drop(['year'], axis=1)xxxxxxxxxxsouth_asian_countries=["India","Nepal","Bangladesh","Pakistan","Afghanistan","Maldives","Sri Lanka","Bhutan"]xxxxxxxxxxnew_df2 = new_df1[new_df1["Country name"].isin(south_asian_countries)]xxxxxxxxxxnew_df2xxxxxxxxxx##### Ranking and visualizing the countries on the basis of life ladder indexxxxxxxxxxxLife_Ladder2=new_df2[["Country name","Life Ladder"]]xxxxxxxxxxLife_Ladder2=Life_Ladder2.sort_values(by=['Life Ladder'], ascending=False)xxxxxxxxxxLife_Ladder2['rank'] =Life_Ladder2.iloc[:,1].rank(ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(Life_Ladder2,colorscale=colorscale)fig.show()xxxxxxxxxx##### Ranking and visualizing the countries on the basis of Social support indexxxxxxxxxxxLife = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(Life,x="year",y="Life Ladder",color="Country name",template="plotly_dark")xxxxxxxxxxxxxxxxxxxxSocial_support=new_df2[['Country name','Social support']]xxxxxxxxxxSocial_support['rank'] =Social_support.iloc[:,1].rank(ascending=False)xxxxxxxxxxSocial_support=Social_support.sort_values(by=['Social support'], ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(Social_support,colorscale=colorscale)fig.show()xxxxxxxxxxSupport = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(Support,x="year",y="Social support",color="Country name",template="plotly_dark")xxxxxxxxxx##### Ranking and visualizing the countries on the basis of Log GDP per capita indexxxxxxxxxxxLGdp_Percapita =new_df2[["Country name","Log GDP per capita"]]xxxxxxxxxxLGdp_Percapita['rank'] =LGdp_Percapita.iloc[:,1].rank(ascending=False)xxxxxxxxxxLGdp_Percapita=LGdp_Percapita.sort_values(by=['Log GDP per capita'], ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(LGdp_Percapita, colorscale=colorscale)fig.show()xxxxxxxxxxLGDP = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(LGDP,x="year",y="Log GDP per capita",color="Country name",template="plotly_dark")xxxxxxxxxx## Ranking and visualizing the countries on the basis of the healthy life expectancy at birth indexxxxxxxxxxxHealthy_life=new_df2[["Country name","Healthy life expectancy at birth"]]xxxxxxxxxxHealthy_life['rank'] =Healthy_life.iloc[:,1].rank(ascending=False)xxxxxxxxxxHealthy_life=Healthy_life.sort_values(by=['Healthy life expectancy at birth'], ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(Healthy_life, colorscale=colorscale)fig.show()xxxxxxxxxxHealthy = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(Healthy,x="year",y="Healthy life expectancy at birth",color="Country name",template="plotly_dark")xxxxxxxxxx##### Ranking and visualizing the countries on the basis of freedom to make life choices indexxxxxxxxxxxLife_choices=new_df2[["Country name","Freedom to make life choices"]]xxxxxxxxxxLife_choices['rank'] =Life_choices.iloc[:,1].rank(ascending=False)xxxxxxxxxxLife_choices=Life_choices.sort_values(by=['Freedom to make life choices'], ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(Life_choices, colorscale=colorscale)fig.show()xxxxxxxxxxLife_choice = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(Life_choice,x="year",y="Freedom to make life choices",color="Country name",template="plotly_dark")xxxxxxxxxx##### Ranking and visualizing the countries on the basis of the Generosity indexxxxxxxxxxxGenerosity=new_df2[["Country name","Generosity"]]xxxxxxxxxxGenerosity['rank'] =Generosity.iloc[:,1].rank(ascending=False)xxxxxxxxxxGenerosity=Generosity.sort_values(by=['Generosity'], ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(Generosity, colorscale=colorscale)fig.show()xxxxxxxxxxGenerous = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(Generous,x="year",y="Generosity",color="Country name",template="plotly_dark")xxxxxxxxxx##### Ranking and visualizing the countries on the basis of the perceptions of corruption indexxxxxxxxxxxCorruption_perception=new_df2[["Country name","Perceptions of corruption"]]xxxxxxxxxxCorruption_perception['rank'] =Corruption_perception.iloc[:,1].rank(ascending=False)xxxxxxxxxxCorruption_perception=Corruption_perception.sort_values(by=['Perceptions of corruption'], ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(Corruption_perception, colorscale=colorscale)fig.show()xxxxxxxxxxCorruption = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(Corruption,x="year",y="Perceptions of corruption",color="Country name",template="plotly_dark")xxxxxxxxxx##### Ranking and visualizing the countries on the basis of positive affect indexxxxxxxxxxxPositive_affect=new_df2[["Country name","Positive affect"]]xxxxxxxxxxPositive_affect['rank'] =Positive_affect.iloc[:,1].rank(ascending=False)xxxxxxxxxxPositive_affect=Positive_affect.sort_values(by=['Positive affect'], ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(Positive_affect, colorscale=colorscale)fig.show()xxxxxxxxxxpositive = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(positive,x="year",y="Positive affect",color="Country name",template="plotly_dark")xxxxxxxxxx##### Ranking and visualizing the countries on the basis of negative affect indexxxxxxxxxxxNegative_affect=new_df2[["Country name","Negative affect"]]xxxxxxxxxxNegative_affect['rank'] =Negative_affect.iloc[:,1].rank(ascending=False)xxxxxxxxxxNegative_affect=Negative_affect.sort_values(by=['Negative affect'], ascending=False)xxxxxxxxxxcolorscale = [[0, '#004F00'],[.5, '#008B00'],[1, '#ffffff']]fig = ff.create_table(Negative_affect, colorscale=colorscale)fig.show()xxxxxxxxxxNegative = df1[df1["Country name"].isin(south_asian_countries)] plt.figure(figsize=(15,10))px.line(Negative,x="year",y="Negative affect",color="Country name",template="plotly_dark")